﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Long.SpraySCADA
{
    public partial class UserCounterButton : UIUserControl
    {
        private UIStyle Style;
        private Color defaultFillColor;
        private Color defaultRectColor;

        public UserCounterButton()
        {
            InitializeComponent();
            this.Load += UserCounterButton_Load;
        }

        private void UserCounterButton_Load(object? sender, EventArgs e)
        {
            UIExtension.SetStyleManager = SetStyle;

            defaultFillColor = this.btn_Counter.FillColor;
            defaultRectColor = this.btn_Counter.RectColor;
        }

        private void SetStyle(UIStyleManager manager)
        {
            this.btn_Counter.Style = manager.Style;
            Style = manager.Style;
            if (buttonCounterStatus)
            {
                this.btn_Counter.FillColor = this.btn_Counter.FillPressColor;
                this.btn_Counter.FillColor2 = this.btn_Counter.FillPressColor;
                this.RectColor = this.btn_Counter.RectPressColor;
            }
        }

    /*    private string buttonName = "空运行";
        [Browsable(true)] //使属性暴露，显示在属性窗口
        [Category("自定义属性")]
        [Description("按钮的名称")]
        public string ButtonName
        {
            get { return buttonName; }
            set
            {
                buttonName = value;
                this.btn_Counter.Text = buttonName;
            }
        }
*/
        private int buttonCounterSymbol = 61452;
        [Browsable(true)] //使属性暴露，显示在属性窗口
        [Category("自定义属性")]
        [Description("取反按钮标签")]
        public int ButtonCounterSymbol
        {
            get { return buttonCounterSymbol; }
            set
            {
                buttonCounterSymbol = value;
                this.btn_Counter.Symbol = buttonCounterSymbol;
            }
        }



        private bool buttonCounterStatus = true;
        [Browsable(true)] //使属性暴露，显示在属性窗口
        [Category("自定义属性")]
        [Description("取反按钮状态")]
        public bool ButtonCounterStatus
        {
            get { return buttonCounterStatus; }
            set
            {
                buttonCounterStatus = value;
                if (buttonCounterStatus)
                {
                    this.btn_Counter.FillColor = this.btn_Counter.FillPressColor;
                    this.btn_Counter.FillColor2 = this.btn_Counter.FillPressColor;
                    this.RectColor = this.btn_Counter.RectPressColor;
                }
                else
                {
                    // 有两种情况第一种是没有切换主题的状态，一种是切换了主题的状态
                    if (this.btn_Counter.Style != Style)
                    {
                        this.btn_Counter.Style = Style;
                    }
                    else
                    {
                        // 未切换主题的状态，恢复默认颜色
                        this.btn_Counter.FillColor = defaultFillColor;
                        this.btn_Counter.FillColor2 = defaultFillColor;
                        this.btn_Counter.RectColor = defaultRectColor;
                    }
                }
            }
        }

        //绑定变量属性
        private string variableName = "";
        [Browsable(true)] //使属性暴露，显示在属性窗口
        [Category("自定义属性")]
        [Description("获取变量名称")]
        public string VariableName
        {
            get { return variableName; }
            set { variableName = value; }
        }

        //事件暴露外部
        [Browsable(true)]
        [Category("自定义事件")]
        [Description("点击事件")]
        public event EventHandler ClickEvent;
        private void btn_Counter_Click(object sender, EventArgs e)
        {
            ClickEvent?.Invoke(this, e);
        }
    }
}
